package com.elink.enginerring.redis;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;
/**
 * Jedis池化
 * @author Rick
 *
 */
public class MyJedis {
	private static JedisPool pool = null;
	
	private MyJedis() {}
	
	static{
		JedisPoolConfig config = new JedisPoolConfig();
		config.setMaxTotal(20000);
		config.setMaxIdle(-1);
		config.setMaxWaitMillis(5*1000);
		config.setTestOnBorrow(true);
		
		pool = new JedisPool(config, RedisConfig.host, RedisConfig.port,RedisConfig.timeout,RedisConfig.password);
	}

	/**
	 * 获取实例
	 * @return
	 */
	public static Jedis getJedisInstance() {
		return pool.getResource();
	}
	
	/**
	 * 返还jedis到池中
	 * @param jedis
	 */
	@SuppressWarnings("deprecation")
	public static void returnJedis(Jedis jedis){
		 pool.returnResource(jedis);
	}
}
